﻿using DevExpress.Mvvm.DataAnnotations;
using DevExpress.Mvvm.POCO;
using System;
using System.Windows.Media;
using TeBigScreenWpf.Common;
using Timer = System.Timers.Timer;

namespace TeBigScreenWpf.ViewModels
{
    [POCOViewModel]
    public class vmMainWindow
    {
        #region Config

        public virtual Brush WindowCfg_Background { get; set; } = Themes.MainWindow.Background;
        public virtual Brush Title_Foreground { get; set; } = Themes.MainWindow.Title_Foreground;
        public virtual Brush SubTitle_Foreground { get; set; } = Themes.MainWindow.SubTitle_Foreground;

        #endregion Config

        public virtual string LeftCaption { get; set; } = "今日警情";
        public virtual string CurrentDateTime { get; set; }

        private Timer _timer = new Timer(500);

        public static vmMainWindow Create()
        {
            return ViewModelSource.Create(() => new vmMainWindow());
        }

        protected vmMainWindow()
        {
            _timer.Elapsed += _timer_Elapsed;
            _timer.Start();
        }

        private void AccquireDate()
        {
            var dt = DateTime.Now;

            var dow = System.Globalization.DateTimeFormatInfo.CurrentInfo.DayNames[(byte)dt.DayOfWeek];

            CurrentDateTime = $"{dt: HH:mm:ss   yyyy/MM/dd}   {dow}";
        }

        private void _timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            AccquireDate();
        }
    }
}